import os

# 指定目录路径
directory = r"C:\Users\Anyphasy\Downloads\校友活动_百度图1搜索_files"

img_urls = []
moment_id = 1
i=0
temp_img_list=[]
numbers_list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40]

index=0

# 遍历目录中的文件
for filename in os.listdir(directory):
    # 检查文件名是否以"u="开头并且以"JPEG"结尾
    if filename.startswith("u=") and filename.endswith("JPEG"):
        # 1. 添加前缀并输出
        url = "https://img2.baidu.com/it/" + filename
        # print(url)

        temp_img_list.append("'"+url+"'")
        i+=1
        if(i==5):
            sql= f'''
#{numbers_list[index]}号回顾插入图片
update event_review
set review_images = JSON_ARRAY(
{",".join(temp_img_list)}
)
where review_id={numbers_list[index]};
                '''
            print(sql)
            temp_img_list.clear()
            index+=1
            if(index==len(numbers_list)):
                break
            i=0
            
      

        


        

# print("操作完成")
# print('长度为',len(img_urls))